package com.hqyj.mana.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.hqyj.mana.enums.ResultEnum;
import com.hqyj.mana.pojo.HrManagement;
import com.hqyj.mana.pojo.vo.ResultVO;
import com.hqyj.mana.service.PositionService;

@RestController
@RequestMapping("position")
public class PositionController {
	@Autowired
	private PositionService positionService;
	
	@RequestMapping("info.do")
	public ResultVO info(String id){
		List<HrManagement> list = positionService.selectAllHrManagement(id);
		ResultVO resultVO = new ResultVO();
		resultVO.setData(list);
		if(list == null){
			resultVO.setCode(ResultEnum.PARAM_ERROR.getCode());
			resultVO.setMsg(ResultEnum.PARAM_ERROR.getMessage());
			return resultVO;
		}	
		resultVO.setCode(ResultEnum.SUCCESS.getCode());
		resultVO.setMsg(ResultEnum.SUCCESS.getMessage());
		
		return resultVO;
	}
	
	@RequestMapping("delete.do")
	public ResultVO delete(Integer hrId){
		Boolean list = positionService.del(hrId);
		ResultVO resultVO = new ResultVO();
		resultVO.setData(list);
		if(list == false){
			resultVO.setCode(ResultEnum.PARAM_ERROR.getCode());
			resultVO.setMsg(ResultEnum.PARAM_ERROR.getMessage());
			return resultVO;
		}	
		resultVO.setCode(ResultEnum.SUCCESS.getCode());
		resultVO.setMsg(ResultEnum.SUCCESS.getMessage());
		
		return resultVO;
	}
	
	@RequestMapping("insert.do")
	public ResultVO insert(@RequestBody HrManagement hm){
		ResultVO resultVO = new ResultVO();
		Boolean list;
		try{
			list = positionService.add(hm);
		}catch(Exception e){
			e.printStackTrace();
			resultVO.setCode(ResultEnum.DATABASE_ERROR.getCode());
			resultVO.setMsg(ResultEnum.DATABASE_ERROR.getMessage());
			return resultVO;
		}
		resultVO.setData(list);
		if(list == false){
			resultVO.setCode(ResultEnum.PARAM_ERROR.getCode());
			resultVO.setMsg(ResultEnum.PARAM_ERROR.getMessage());
			return resultVO;
		}	
		resultVO.setCode(ResultEnum.SUCCESS.getCode());
		resultVO.setMsg(ResultEnum.SUCCESS.getMessage());
		
		return resultVO;
	}
}
